package org.bbl.db.mybatis.mysql;

import com.google.inject.Singleton;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.bbl.common.ProjectResources;

import java.io.File;
import java.io.Serializable;

/**
 * @author biniamg
 * @since 10/31/12
 */
@Singleton
public class MyDataSource implements Serializable {
    private final SqlSessionFactory sqlSessionFactory;
    File config = ProjectResources.getResourceFile("mybatis.mysql.cfg.xml");
  //  File config = ProjectResources.chainDirs(new File("C:\\markit\\ATF\\src\\main\\resources"),"mybatis.cfg.xml");


    public MyDataSource() {
        this("bbl");
    }

    public MyDataSource(String environment) {
        this.sqlSessionFactory = new MyDBConnectionManager(config, environment).getSqlSessionFactory();
    }

    public SqlSession getSession() {
        return sqlSessionFactory.openSession(true);
    }

}
